package com.itlaobing.util;

import java.util.List;

public class PageUtil<T> {

	//当前页
	private Integer pageIndex=1;
	//每页的大小
	private Integer pageSize=1;
	//总条数
	private Integer recordCount;
	//总页数
	private Integer pageCount;
	//页码数组
	private int[] pageNums;
	//存放结果的集合
	private List<T> datas;
	//前面是否有省略号
	private boolean hasPreOmit;
	//后面是否有省略号
	private boolean hasSuffixOmit;

	//条件
	private String condition;




	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(Integer recordCount) {
		this.recordCount = recordCount;
	}
	public Integer getPageCount() {

		return ((recordCount-1)/pageSize+1);
	}
	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public List<T> getDatas() {
		return datas;
	}
	public void setDatas(List<T> datas) {
		this.datas = datas;
	}


	public boolean isHasPreOmit() {
		return hasPreOmit;
	}
	public void setHasPreOmit(boolean hasPreOmit) {
		this.hasPreOmit = hasPreOmit;
	}
	public boolean isHasSuffixOmit() {
		return hasSuffixOmit;
	}
	public void setHasSuffixOmit(boolean hasSuffixOmit) {
		this.hasSuffixOmit = hasSuffixOmit;
	}

	public int[] getPageNums() {

		return pageNums;
	}

	//设置数组，设置省略号显示的位置
	//displayPageNumber 页码个数
	public void setPageNums(int displayPageNumber) {

		//情况一 ，前后都没有省略号
		if(this.getPageCount()<=displayPageNumber) {

			pageNums=new int[this.getPageCount()];

			for(int i=0;i<this.getPageCount();i++) {
				pageNums[i]=i+1;
			}

			this.setHasPreOmit(false);
			this.setHasSuffixOmit(false);
			//情况二 ，前后都有省略号
		}else if(this.getPageIndex()-displayPageNumber/2>0&&this.getPageIndex()+displayPageNumber/2<this.getPageCount()) {
			pageNums=new int[displayPageNumber];
			for(int i=this.getPageIndex()-displayPageNumber/2,_index=0;i<=this.getPageIndex()+displayPageNumber/2;i++,_index++) {
				pageNums[_index]=i;
			}
			this.setHasPreOmit(true);
			this.setHasSuffixOmit(true);
			//情况三，前有省略号，后没有省略号
		}else if(this.getPageIndex()-displayPageNumber/2>0&&this.getPageIndex()+displayPageNumber/2>=this.getPageCount()) {
			pageNums=new int[displayPageNumber];
			for(int i=this.getPageCount()-displayPageNumber+1,_index=0;i<=this.getPageCount();i++,_index++) {
				pageNums[_index]=i;
			}
			this.setHasPreOmit(true);
			this.setHasSuffixOmit(false);
			//情况三，前没有省略号，后有省略号
		}else {
			pageNums=new int[displayPageNumber];
			for(int i=0;i<displayPageNumber;i++) {
				pageNums[i]=i+1;
			}
			this.setHasPreOmit(false);
			this.setHasSuffixOmit(true);
		}

	}

}